class Level
{
	public static function createLevel(level:int, cm:CharacterManager, map:Map)
	{
		switch (level)
		{
			case 1:
				this.generateLevel1(cm, map);
				break;
				
			case 2:
				this.generateLevel2(cm, map);
				break;
		}

	}
	
	private static function generateLevel1(cm:CharacterManager, map:Map)
	{
		var _mg:MapGenerator = new MapGenerator();
		_mg.setMapSize(30,60);
		
		//set FlatsPos(start x, end x, start y, end y, height)
		//HEIGHT MAP
		//lower middle part of the map
		_mg.setFlatsPos(12,17,15,22,1);//h1
		_mg.setFlatsPos(13,16,16,21,2);//h2
		//top left corner of map
		_mg.setFlatsPos(1,13,28,37,1);//h3
		_mg.setFlatsPos(1,13,50,58,1);//h5
		_mg.setFlatsPos(1,12,28,58,2);//h4
		
		//OBSTACLES
		//Set fixedObstacle(position x, position y, obstacle type)
		_mg.setFixedObstacle(13,4,0); 	//a1
		_mg.setFixedObstacle(19,4,0); 	//a2
		_mg.setFixedObstacle(19,6,0); 	//a3
		_mg.setFixedObstacle(15,16,0);	//a4
		_mg.setFixedObstacle(16,20,0); 	//a5
		_mg.setFixedObstacle(15,21,0); 	//a6
		_mg.setFixedObstacle(10,36,0); 	//a7
		_mg.setFixedObstacle(7,2,0); 	//a8
		_mg.setFixedObstacle(15,7,0); 	//a9
		_mg.setFixedObstacle(12,11,0);	//a10
		_mg.setFixedObstacle(21,14,0); 	//a11
		_mg.setFixedObstacle(2,22,0); 	//a12
		_mg.setFixedObstacle(6,30,0); 	//a13
		_mg.setFixedObstacle(7,35,0); 	//a14
		_mg.setFixedObstacle(14,54,0); 	//a15
		_mg.setFixedObstacle(22,44,0); 	//a16
		_mg.setFixedObstacle(16,46,0); 	//a17
		_mg.setFixedObstacle(15,49,0); 	//a18
		_mg.setFixedObstacle(17,38,0); 	//a19
		_mg.setFixedObstacle(27,29,0); 	//a20
		_mg.setFixedObstacle(23,26,0); 	//a21
		_mg.setFixedObstacle(14,29,0); 	//a22
		_mg.setFixedObstacle(13,27,0); 	//a23
		_mg.setFixedObstacle(10,16,0); 	//a24	
		_mg.setFixedObstacle(11,7,0); 	//a25		
		_mg.setFixedObstacle(9,21,0); 	//a26	
		_mg.setFixedObstacle(11,5,0); 	//a27	
		_mg.setFixedObstacle(4,4,0); 	//a28
		_mg.setFixedObstacle(3,4,0); 	//a29
		_mg.setFixedObstacle(2,6,0); 	//a30
		_mg.setFixedObstacle(5,7,0); 	//a31
		_mg.setFixedObstacle(5,8,0); 	//a32
		_mg.setFixedObstacle(5,13,0); 	//a33
		_mg.setFixedObstacle(11,8,0); 	//a34
		_mg.setFixedObstacle(17,5,0); 	//a35
		_mg.setFixedObstacle(15,4,0); 	//a36
		_mg.setFixedObstacle(14,10,0); 	//a37
		_mg.setFixedObstacle(1,18,0); 	//a38
		_mg.setFixedObstacle(3,21,0); 	//a39
		_mg.setFixedObstacle(20,10,0); 	//a40
		_mg.setFixedObstacle(28,19,0); 	//a41
		_mg.setFixedObstacle(2,2,0); 	//a42
		_mg.setFixedObstacle(25,22,0); 	//a43
		_mg.setFixedObstacle(19,19,0); 	//a44
		_mg.setFixedObstacle(1,27,0); 	//a45
		_mg.setFixedObstacle(4,39,0); 	//a46
		_mg.setFixedObstacle(2,52,0); 	//a47
		_mg.setFixedObstacle(8,47,0); 	//a48
		_mg.setFixedObstacle(7,54,0); 	//a49
		_mg.setFixedObstacle(19,30,0); 	//a50
		_mg.setFixedObstacle(21,33,0); 	//a51
		_mg.setFixedObstacle(19,36,0); 	//a52
		_mg.setFixedObstacle(22,37,0); 	//a53
		_mg.setFixedObstacle(23,37,0); 	//a54
		_mg.setFixedObstacle(14,40,0); 	//a55
		_mg.setFixedObstacle(18,41,0); 	//a56
		_mg.setFixedObstacle(3,9,0); 	//a57
		_mg.setFixedObstacle(14,45,0); 	//a58
		_mg.setFixedObstacle(16,30,0); 	//a59
		_mg.setFixedObstacle(2,36,0); 	//a60
		_mg.setFixedObstacle(7,4,0); 	//a61
		_mg.setFixedObstacle(19,15,0); 	//a62
		_mg.setFixedObstacle(20,57,0); 	//a63
		_mg.setFixedObstacle(24,33,0); 	//a64
		_mg.setFixedObstacle(27,33,0); 	//a65
		_mg.setFixedObstacle(25,6,0); 	//a66
		_mg.setFixedObstacle(27,5,0); 	//a67
		_mg.setFixedObstacle(22,3,0); 	//a68
		_mg.setFixedObstacle(21,8,0); 	//a69
		_mg.setFixedObstacle(17,9,0); 	//a70
		_mg.setFixedObstacle(10,24,0); 	//a71
		_mg.setFixedObstacle(23,23,0); 	//a72
		_mg.setFixedObstacle(6,10,0); 	//a73
		_mg.setFixedObstacle(11,14,0); 	//a74
		_mg.setFixedObstacle(13,8,0); 	//a75
		_mg.setFixedObstacle(3,17,0); 	//a76
		_mg.setFixedObstacle(18,33,0); 	//a77
		_mg.setFixedObstacle(15,37,0); 	//a78
		_mg.setFixedObstacle(22,48,0); 	//a79
		_mg.setFixedObstacle(23,46,0); 	//a80
		_mg.setFixedObstacle(22,51,0); 	//a81
		_mg.setFixedObstacle(9,31,0); 	//a82
		_mg.setFixedObstacle(4,31,0); 	//a83
		_mg.setFixedObstacle(5,36,0); 	//a84
		_mg.setFixedObstacle(15,12,0); 	//a85
		_mg.setFixedObstacle(21,19,0); 	//a86
		_mg.setFixedObstacle(23,21,0); 	//a87
		_mg.setFixedObstacle(25,20,0); 	//a88
		_mg.setFixedObstacle(8,19,0); 	//a88
		
		_mg.setFixedObstacle(9,5,2); 	//b1
		_mg.setFixedObstacle(13,19,2); 	//b2
		_mg.setFixedObstacle(10,34,2); 	//b3
		_mg.setFixedObstacle(8,15,2); 	//b4
		_mg.setFixedObstacle(27,19,2); 	//b5
		_mg.setFixedObstacle(18,25,2); 	//b6
		_mg.setFixedObstacle(2,42,2); 	//b7
		_mg.setFixedObstacle(12,56,2); 	//b8
		_mg.setFixedObstacle(27,42,2); 	//b9
		_mg.setFixedObstacle(7,23,2); 	//b10
		_mg.setFixedObstacle(27,37,2); 	//b11
		
		_mg.setFixedObstacle(4,25,1); 	//c1
		_mg.setFixedObstacle(18,27,1); 	//c2
		_mg.setFixedObstacle(3,41,1); 	//c3
		_mg.setFixedObstacle(5,45,1); 	//c4
		_mg.setFixedObstacle(7,57,1); 	//c5
		_mg.setFixedObstacle(24,39,1); 	//c6
		_mg.setFixedObstacle(2,11,1); 	//c7
		_mg.setFixedObstacle(24,16,1); 	//c8
		_mg.setFixedObstacle(26,25,1); 	//c9
		_mg.setFixedObstacle(26,45,1); 	//c10
		_mg.setFixedObstacle(19,45,1); 	//c11
		_mg.setFixedObstacle(6,27,1); 	//c12
		_mg.setFixedObstacle(22,5,1); 	//c13
		_mg.setFixedObstacle(16,57,1); 	//c14
		_mg.setFixedObstacle(26,35,1); 	//c15
		_mg.setFixedObstacle(26,3,1); 	//c16
		_mg.setFixedObstacle(6,18,1); 	//c17
		
		_mg.setFixedObstacle(7,7,4); 	//t1
		_mg.setFixedObstacle(17,11,4); 	//t2
		_mg.setFixedObstacle(3,15,4); 	//t3
		_mg.setFixedObstacle(10,26,4); 	//t4
		_mg.setFixedObstacle(21,23,4); 	//t5
		_mg.setFixedObstacle(25,28,4); 	//t6
		_mg.setFixedObstacle(21,40,4); 	//t7
		_mg.setFixedObstacle(16,42,4); 	//t8
		_mg.setFixedObstacle(7,42,4); 	//t9
		_mg.setFixedObstacle(2,38,4); 	//t10
		_mg.setFixedObstacle(16,52,4); 	//t11
		_mg.setFixedObstacle(9,55,4); 	//t12		
		
		//_mg.setFixedObstacle(20,11,3); 	//w2
		//_mg.setFixedObstacle(23,11,3); 	//w3
		//_mg.setFixedObstacle(26,11,3); 	//w4
		_mg.setFixedObstacle(10,49,3); 	//w5
		_mg.setFixedObstacle(10,45,3); 	//w6
		_mg.setFixedObstacle(10,41,3); 	//w7
		
		_mg.setFixedObstacle(23,8,5); 	//HOUSE1
		_mg.setFixedObstacle(25,52,5); 	//HOUSE
		
		//Set obstacleBound(start x, end x , start y, end y, number of obstacles, obstacle type)
		_mg.setObstacleBound(7,9,9,12,3,0); 	//r1
		_mg.setObstacleBound(22,24,18,20,3,0); 	//r2
		_mg.setObstacleBound(15,17,32,35,3,1); 	//r3
		_mg.setObstacleBound(1,3,46,49,3,1); 	//r4
		_mg.setObstacleBound(12,14,23,26,3,0); 	//r5
		_mg.setObstacleBound(1,3,30,33,3,2); 	//r6
		_mg.setObstacleBound(6,8,37,40,2,1); 	//r7
		_mg.setObstacleBound(6,8,49,52,4,0); 	//r8
		_mg.setObstacleBound(19,21,47,50,2,2); 	//r9
		_mg.setObstacleBound(18,20,52,55,3,0); 	//r10
		_mg.setObstacleBound(24,26,47,50,3,1); 	//r11
		_mg.setObstacleBound(19,21,9,12,3,0); 	//r12
		
		
		//set HillPos(middle of hill x, middle of hill y)
		//_mg.setHillPos(10,10);
		//Set SandPatch(start x, start y, radius)
		//_mg.setSandPatch(5,5,5);
		map.setMap(_mg.generateMap());
		cm.setupMap(map);
		
		cm.spawnPlayer(MenuScreen.slot1ID, map.getTile(9,2));	//s1
		cm.spawnPlayer(MenuScreen.slot2ID, map.getTile(11,2));	//s2
		cm.spawnPlayer(MenuScreen.slot3ID, map.getTile(13,2));	//s3
		// For testing and seeing the enemy spawn..OLD/ACTUAL COORDINATE IS BESIDE AS COMMENTED
		/*
		cm.spawnPlayer(MenuScreen.slot4ID, map.getTile(3,7));	//s4 23,4
		cm.spawnPlayer(MenuScreen.slot5ID, map.getTile(5,34));	//s5 25,4
		cm.spawnPlayer(MenuScreen.slot6ID, map.getTile(23,33));	//s6 27,4
		*/
		cm.spawnPlayer(MenuScreen.slot4ID, map.getTile(15,2));	//s4 23,4
		cm.spawnPlayer(MenuScreen.slot5ID, map.getTile(17,2));	//s5 25,4
		cm.spawnPlayer(MenuScreen.slot6ID, map.getTile(19,2));	//s6 27,4
		// End of Spawn Player ========
		
		// ER1 ========================
		var x1:int = Random.Range(13, 16);
		var y1:int = Random.Range(13, 14);
		var x2:int = Random.Range(13, 16);
		var y2:int = Random.Range(13, 14);
		while(x2 == x1 && y2 == y1) {
			x2 = Random.Range(13, 16);
			y2 = Random.Range(13, 14);
		}
		
		cm.spawnEnemy(getEnemyType(), map.getTile(x1,y1));
		cm.spawnEnemy(getEnemyType(), map.getTile(x2,y2));
		
		// End of ER1 =================
		
		// ER2 ========================
		x1 = Random.Range(4, 6);
		y1 = Random.Range(32, 35);
		x2 = Random.Range(4, 6);
		y2 = Random.Range(32, 35);
		while(x2 == x1 && y2 == y1) {
			x2 = Random.Range(4, 6);
			y2 = Random.Range(32, 35);
		}
		cm.spawnEnemy(getEnemyType(), map.getTile(x1, y1)); // 4,34
		cm.spawnEnemy(getEnemyType(), map.getTile(x2, y2)); // 3,32
		// End of ER2 =================
		
		// Fixed enemies position
		cm.spawnEnemy(getEnemyType(), map.getTile(3,56));//e1
		cm.spawnEnemy(getEnemyType(), map.getTile(5,56));//e2
		cm.spawnEnemy(getEnemyType(), map.getTile(3,54));//e3
		cm.spawnEnemy(getEnemyType(), map.getTile(5,54));//e4
		cm.spawnEnemy(getEnemyType(), map.getTile(16,55));//e5
		cm.spawnEnemy(getEnemyType(), map.getTile(19,43));//e6
		cm.spawnEnemy(getEnemyType(), map.getTile(16,43));//e7
		cm.spawnEnemy(getEnemyType(), map.getTile(6,21));//e8
		cm.spawnEnemy(getEnemyType(), map.getTile(23,35));//e9
		cm.spawnEnemy(getEnemyType(), map.getTile(20,17));//e10
		cm.spawnEnemy(getEnemyType(), map.getTile(26,16));//e11
		cm.spawnEnemy(getEnemyType(), map.getTile(2,17));//e12
		cm.spawnEnemy(getEnemyType(), map.getTile(6,14));//e13
		cm.spawnEnemy(getEnemyType(), map.getTile(10,19));//e14
		cm.spawnEnemy(getEnemyType(), map.getTile(21,21));//e15
		cm.spawnEnemy(getEnemyType(), map.getTile(8,25));//e16
		cm.spawnEnemy(getEnemyType(), map.getTile(19,28));//e17
		cm.spawnEnemy(getEnemyType(), map.getTile(25,26));//e18
		cm.spawnEnemy(getEnemyType(), map.getTile(23,31));//e19
		cm.spawnEnemy(getEnemyType(), map.getTile(3,21));//e20
		cm.spawnEnemy(getEnemyType(), map.getTile(20,13));//e21
		cm.spawnEnemy(getEnemyType(), map.getTile(17,49));//e22
		cm.spawnEnemy(getEnemyType(), map.getTile(6,46));//e23

	}
	
	private static function generateLevel2(cm:CharacterManager, map:Map)
	{
		var _mg:MapGenerator = new MapGenerator();
		_mg.setMapSize(15,34);
		
		//set FlatsPos(start x, end x, start y, end y, height)
		//HEIGHT MAP
		_mg.setFlatsPos(4,11,16,20,1);//h1
		_mg.setFlatsPos(4,6,17,20,2);//h2
		_mg.setFlatsPos(4,6,18,20,3);//h3
		_mg.setFlatsPos(9,11,18,20,2);//h4
		_mg.setFlatsPos(8,12,28,32,1);//h5
		_mg.setFlatsPos(8,10,29,31,2);//h6
		
		//FIXED OBSTACLES
		//Set fixedObstacle(position x, position y, obstacle type)
		_mg.setFixedObstacle(2,5,0); 	//a1
		_mg.setFixedObstacle(4,5,0); 	//a2
		_mg.setFixedObstacle(6,5,0); 	//a3
		_mg.setFixedObstacle(9,5,0); 	//a4
		_mg.setFixedObstacle(11,5,0); 	//a5
		_mg.setFixedObstacle(13,5,0); 	//a6
		_mg.setFixedObstacle(7,11,0); 	//a7
		_mg.setFixedObstacle(9,11,0); 	//a8
		_mg.setFixedObstacle(10,13,0); 	//a9
		_mg.setFixedObstacle(1,20,0); 	//a10
		_mg.setFixedObstacle(3,20,0); 	//a11
		_mg.setFixedObstacle(6,20,0); 	//a12
		_mg.setFixedObstacle(11,22,0); 	//a13
		_mg.setFixedObstacle(4,22,0); 	//a14
		_mg.setFixedObstacle(13,23,0); 	//a15
		_mg.setFixedObstacle(1,23,0); 	//a16
		_mg.setFixedObstacle(5,25,0); 	//a17
		_mg.setFixedObstacle(5,27,0); 	//a18
		_mg.setFixedObstacle(8,26,0); 	//a19
		_mg.setFixedObstacle(1,17,0);	//a20
		
		_mg.setFixedObstacle(2,8,2); 	//b1
		_mg.setFixedObstacle(13,8,2); 	//b2
		_mg.setFixedObstacle(4,12,2); 	//b3
		_mg.setFixedObstacle(13,16,2); 	//b4
		_mg.setFixedObstacle(5,30,2); 	//b5
		_mg.setFixedObstacle(2,17,2);	//b6
		
		_mg.setFixedObstacle(5,8,1); 	//c1
		_mg.setFixedObstacle(10,8,1); 	//c2
		_mg.setFixedObstacle(2,13,1); 	//c3
		_mg.setFixedObstacle(10,20,1); 	//c4
		_mg.setFixedObstacle(2,28,1); 	//c5
		_mg.setFixedObstacle(2,32,1); 	//c6
		
		//_mg.setFixedObstacle(1,16,3); 	//w1
		_mg.setFixedObstacle(7,23,3); 	//w2
		
		//RANDOM OBSTACLES
		//Set obstacleBound(start x, end x , start y, end y, number of obstacles, obstacle type)
		_mg.setObstacleBound(11,14,11,13,4,0); 	//r1
		_mg.setObstacleBound(12,14,24,26,4,0); 	//r2
		_mg.setObstacleBound(1,2,24,26,3,0); 	//r3
		_mg.setObstacleBound(8,12,28,32,7,0); 	//r4
		
		map.setMap(_mg.generateMap());
		cm.setupMap(map);
		
		//Spawn player
		cm.spawnPlayer(MenuScreen.slot1ID, map.getTile(2,1));	//s1
		cm.spawnPlayer(MenuScreen.slot2ID, map.getTile(4,1));	//s2
		cm.spawnPlayer(MenuScreen.slot3ID, map.getTile(6,1));	//s3
		cm.spawnPlayer(MenuScreen.slot4ID, map.getTile(9,1));	//s4 
		cm.spawnPlayer(MenuScreen.slot5ID, map.getTile(11,1));	//s5 
		cm.spawnPlayer(MenuScreen.slot6ID, map.getTile(13,1));	//s6 
		
		// Fixed enemies position
		cm.spawnEnemy(2, map.getTile(7,13));//e1 RANGE
		cm.spawnEnemy(getEnemyType(), map.getTile(3, 25)); //e2
		cm.spawnEnemy(getEnemyType(), map.getTile(4, 25)); //e3
		cm.spawnEnemy(getEnemyType(), map.getTile(7, 25)); //e4
		cm.spawnEnemy(getEnemyType(), map.getTile(8, 25)); //e5
		cm.spawnEnemy(getEnemyType(), map.getTile(10, 25)); //e6
		cm.spawnEnemy(getEnemyType(), map.getTile(11, 25)); //e7
		cm.spawnEnemy(getEnemyType(), map.getTile(2, 30)); //e8
		cm.spawnEnemy(getEnemyType(), map.getTile(3, 30)); //e9
	}
	
	
	private static function getEnemyType(){
		var x1:int = Random.Range(1, 5);
		
		if(x1 == 1){
			return CharacterManager.ENEMY_MELEE;
		}else if(x1 == 2){
			return CharacterManager.ENEMY_RANGE;
		}else if(x1 == 3){
			return CharacterManager.ENEMY_HEALER;
		}else{
			return CharacterManager.ENEMY_SPELL;
		}
}

}